package com.cskaoyan.bean.promotion.coupon;

import com.cskaoyan.util.DateUtils;

import java.lang.Double;
import java.util.Date;
import java.util.List;

/**
 * 优惠卷信息及规则
 */

public class Coupon {

    private Integer id;
    //优惠券名称
    private String name;
    //优惠券介绍，通常是显示优惠券使用限制文字
    private String desc;
    //优惠券标签，例如新人专用
    private String tag;
    //优惠券数量，如果是0，则是无限量
    private Integer total;
    //优惠金额
    private Double discount;
    //最少消费金额才能使用优惠券。
    private Double min;
    //用户领券限制数量，如果是0，则是不限制；默认是1，限领一张.'
    private Short limit;
    //优惠券赠送类型，如果是0则通用券，用户领取；
    // 如果是1，则是注册赠券；如果是2，则是优惠券码兑换
    private Short type;
    //优惠券状态，如果是0则是正常可用；
    // 如果是1则是过期; 如果是2则是下架。
    private Short status;
    //商品限制类型，如果0则全商品，
    // 如果是1则是类目限制，如果是2则是商品限制。
    private Short goodsType;
    //'商品限制值，goods_type如果是0则空集合，
    // 如果是1则是类目集合，如果是2则是商品集合。
    private Integer[] goodsValue;
    //优惠券兑换码
    private String code;
    //'有效时间限制，如果是0，则基于领取时间的有效天数days
    // ；如果是1，则start_time和end_time是优惠券有效期；',
    private Short timeType;
    //'基于领取时间的有效天数days。
    private Short days;
    //
    private Date startTime;

    private Date endTime;

    private Date addTime;

    private Date updateTime;
    //逻辑删除
    private Boolean deleted;

    public Coupon() {
    }

    public Coupon(Integer id, String name, String desc, String tag, Integer total,
                  Double discount, Double min, Short limit, Short type, Short status,
                  Short goodsType, Integer[] goodsValue, String code, Short timeType,
                  Short days, Date startTime, Date endTime, Date addTime, Date updateTime, Boolean deleted) {
        this.id = id;
        this.name = name;
        this.desc = desc;
        this.tag = tag;
        this.total = total;
        this.discount = discount;
        this.min = min;
        this.limit = limit;
        this.type = type;
        this.status = status;
        this.goodsType = goodsType;
        this.goodsValue = goodsValue;
        this.code = code;
        this.timeType = timeType;
        this.days = days;
        this.startTime = startTime;
        this.endTime = endTime;
        this.addTime = addTime;
        this.updateTime = updateTime;
        this.deleted = deleted;
    }

    //时间datetype和timetype区分呢开

    public Coupon(UpdateCouponBO couponBO) {
        this.id = couponBO.getId();
        this.name = couponBO.getName();
        this.desc = couponBO.getDesc();
        this.tag = couponBO.getTag();
        this.total = couponBO.getTotal();
        this.discount = couponBO.getDiscount();
        this.min = couponBO.getMin();
        this.limit = couponBO.getLimit();
        this.type = couponBO.getType();
        this.status = couponBO.getStatus();
        this.goodsType = couponBO.getGoodsType();
        List<UpdateCouponGoods> couponGoodsList = couponBO.getCouponGoodsList();
        if (couponGoodsList != null && couponGoodsList.size() > 0) {
            Integer[] goodsIds = new Integer[couponGoodsList.size()];
            for (int i = 0; i < couponGoodsList.size(); i++) {
                goodsIds[i] = couponGoodsList.get(i).getGoodsId();
            }
            this.goodsValue = goodsIds;
        }
        this.timeType = couponBO.getTimeType();
        this.days = couponBO.getDays();
        if (couponBO.getStartTime() != null) {
            this.startTime = DateUtils.parseDate(couponBO.getStartTime());
        }
        if (couponBO.getEndTime() != null) {
            this.endTime = DateUtils.parseDate(couponBO.getEndTime());
        }
        if (couponBO.getAddTime() != null) {
            this.addTime = DateUtils.parseDate(couponBO.getAddTime());
        }
        this.updateTime = new Date();
        this.deleted = couponBO.getDeleted();

    }

    public Coupon(CreateCouponBO couponBO) {
        this.name = couponBO.getName();
        this.desc = couponBO.getDesc();
        this.tag = couponBO.getTag();
        this.total = couponBO.getTotal();
        this.discount = couponBO.getDiscount();
        this.min = couponBO.getMin();
        this.limit = couponBO.getLimit();
        this.type = couponBO.getType();
        this.status = couponBO.getStatus();
        this.goodsType = couponBO.getGoodsType();
        this.goodsValue = couponBO.getGoodsValue();
        this.timeType = couponBO.getTimeType();
        this.days = couponBO.getDays();
        if (couponBO.getStartTime() != null) {
            this.startTime = DateUtils.parseDate(couponBO.getStartTime());
        }
        if (couponBO.getEndTime() != null) {
            this.endTime = DateUtils.parseDate(couponBO.getEndTime());
        }
        this.addTime = new Date();
        this.updateTime = new Date();
        this.deleted = false;
    }

    //检查跟新后 done 优惠时间根据优惠类型时间改变
    public void checkUpdateDay(Coupon coupon) {
        if (coupon.getTimeType() == 0) {
            coupon.setStartTime(coupon.addTime);
            coupon.setEndTime(DateUtils.addDayOfDate(coupon.getAddTime(), coupon.days));
        } else {
            coupon.setDays((short) DateUtils.getDisDay(coupon.getStartTime(), coupon.getEndTime()));
        }

    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    public Double getDiscount() {
        return discount;
    }

    public void setDiscount(Double discount) {
        this.discount = discount;
    }

    public Double getMin() {
        return min;
    }

    public void setMin(Double min) {
        this.min = min;
    }

    public Short getLimit() {
        return limit;
    }

    public void setLimit(Short limit) {
        this.limit = limit;
    }

    public Short getType() {
        return type;
    }

    public void setType(Short type) {
        this.type = type;
    }

    public Short getStatus() {
        return status;
    }

    public void setStatus(Short status) {
        this.status = status;
    }

    public Short getGoodsType() {
        return goodsType;
    }

    public void setGoodsType(Short goodsType) {
        this.goodsType = goodsType;
    }

    public Integer[] getGoodsValue() {
        return goodsValue;
    }

    public void setGoodsValue(Integer[] goodsValue) {
        this.goodsValue = goodsValue;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Short getTimeType() {
        return timeType;
    }

    public void setTimeType(Short timeType) {
        this.timeType = timeType;
    }

    public Short getDays() {
        return days;
    }

    public void setDays(Short days) {
        this.days = days;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Date getAddTime() {
        return addTime;
    }

    public void setAddTime(Date addTime) {
        this.addTime = addTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }
}